﻿
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;

namespace MNH.WebApps.Common.Helpers.JqGrid
{
  [DataContract]
  public class Filter
  {
    [DataMember]
    public string groupOp { get; set; }

    [DataMember]
    public Rule[] rules { get; set; }

    public static Filter Create(string jsonData)
    {
      try
      {
        return new DataContractJsonSerializer(typeof (Filter)).ReadObject((Stream) new MemoryStream(Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(jsonData)))) as Filter;
      }
      catch
      {
        return (Filter) null;
      }
    }
  }
}
